﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AuthorInqury//这个是注册页面，子窗体
{
    public partial class Register1 : Form
    {
        private string text1;
        private string text2;

        public Register1()
        {
            InitializeComponent();
        }

        public Register1(string text)
        {
            Text = text;
        }

        public Register1(string text, string text1, string text2) : this(text)
        {
            this.text1 = text1;
            this.text2 = text2;
        }

        //这里也需要文本框的内容，也需要被调用
        public void SetInfo(string info)
        {
            this.textBox1.Text = info;
            this.textBox2.Text = info;
            this.textBox3.Text = info;
        }

        private void label1_Click(object sender, EventArgs e)
        {
            //标题无视，不需要
        }

        private void button1_Click(object sender, EventArgs e)//注册按钮，需要出现注册成功提示！
        {
            string name = this.textBox1.Text;//用户名称
            string pwd = this.textBox2.Text;//用户密码
            string repwd = this.textBox3.Text;//再次确认用户密码
            if(name.Contains(" "))
            {
                MessageBox.Show("用户名称不能含有空格","内容错误");
                return;
            }
            if(name.Length<6)
            {
                MessageBox.Show("用户名称不能少于6个字！ ", "且不能包含空格等非法字符！");
                return;
            }
            if(pwd.Length<6)
            {
                MessageBox.Show("密码不能少于6个字符！", "密码尽可能要复杂");
                return;
            }
            if(pwd!=repwd)//判断密码是否一样
            {
                MessageBox.Show("两者密码不一样！","请重新输入");
            }
            string info = name + "\r\n" + pwd + "\r\n" + repwd;//输出内容
            Register1 register1 = new Register1(textBox1.Text,textBox2.Text,textBox3.Text);
            register1.ShowDialog();
            if(this.textBox1.Text.Trim()=="何嘉滨滨滨滨"&&this.textBox2.Text.Trim()=="123456"&&textBox3.Text==textBox2.Text)
                //要对比验证密码是否正确
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
                MessageBox.Show("注册成功", "恭喜你完成注册");
            }
            else
            {
                MessageBox.Show("两次密码输入有误!","请重新输入");
            }
          
        }

        private void button2_Click(object sender, EventArgs e)//取消按钮，出现是否取消注册，yesno，if判断，如果yes则退出当前窗体
            //若为no则继续停留在此页面
        {
            DialogResult DR = MessageBox.Show("是否取消注册", "确认取消", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if(DR==DialogResult.Yes)
            {
                Application.Exit();//程序退出
            }
            else
            {
                this.textBox1.Text = "";
                this.textBox2.Text = "";
                this.textBox3.Text = "";
            }
        }
    }
}
